/*
 * @Author: szx
 * @Date: 2021-12-05 14:15:04
 * @LastEditTime: 2021-12-05 14:21:30
 * @Description:
 * @FilePath: \leetcode\1-99\19\19.js
 */

function ListNode(val, next) {
    this.val = val === undefined ? 0 : val;
    this.next = next === undefined ? null : next;
}

/**
 * @param {ListNode} head
 * @param {number} n
 * @return {ListNode}
 */
var removeNthFromEnd = function (head, n) {
    let dummy = new ListNode(-1, head);
    let fast = dummy;
    for (let i = 0; i < n; i++) {
        fast = fast.next;
    }
    let cur = dummy;
    while (fast.next != null) {
        cur = cur.next;
        fast = fast.next;
    }
    cur.next = cur.next.next;
    return dummy.next;
};
